#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int d[N],v[N],a[N],f[N],type[N],p[N];
vector<pair<int,int> > vec;

bool cmp(pair<int,int> p1,pair<int,int> p2){
    return p1.second<p2.second;
}

void solve(){
    vec.clear();
    memset(type,0,sizeof(type));
    int n,m,L,V;
    cin>>n>>m>>L>>V;
    for(int i=1;i<=n;i++)
    {
        cin>>d[i]>>v[i]>>a[i];
        if(a[i]>0){
            f[i]=d[i]+(V*V-v[i]*v[i]+2*a[i]-1)/2/a[i];
            if(f[i]<=L)
                type[i]=1;
        }
        else if(a[i]<0){
            f[i]=d[i]+(V*V-v[i]*v[i])/2/a[i];
            if(v[i]>V)
                type[i]=2;
        }
        else if(a[i]==0&&v[i]>V)f[i]=d[i],type[i]=3;
    }
    for(int i=1;i<=m;i++)cin>>p[i];
    sort(p+1,p+n+1);
    bool fl=0;
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(type[i]==1&&f[i]<=p[m]){
            cnt++;
            int *P=lower_bound(p,p+m+1,f[i]);
            int u=P-p-1;
            vec.push_back({u+1,m});
        }
        else if(type[i]==2){
            int *P=lower_bound(p,p+m+1,f[i]);
            int t=P-p-1;
            if(p[t]<d[i])continue;
            int *Q=lower_bound(p,p+m+1,d[i]);
            int u=Q-p-1;
            vec.push_back({u+1,t});
            cnt++;
        }
        else if(type[i]==3&&d[i]<=p[m])
        {
            cnt++;
            int *P=lower_bound(p,p+m+1,f[i]);
            int u=P-p-1;
            vec.push_back({u+1,m});
        }
    }
    cout<<cnt<<' ';
    cnt=0;
    sort(vec.begin(),vec.end(),cmp);
    int pre=-1;
    for(int i=0;i<vec.size();i++)
        if(vec[i].first>pre){
            cnt++;
            pre=vec[i].second;
        }
    cout<<m-cnt<<'\n';
}

signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int _;
    cin>>_;
    while(_--)
        solve();
    return 0;
}
